var common = require("../../utils/common.js");
var app=getApp();
// pages/detail/detail.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    bannerList:[],
    data:[],
    tips: [],
    updateTime:'',
    houseType:'',
    zhoubian_num:1,
    longitude: 118.6648443788737,
    latitude: 31.90991590886252,
    isLa:false,
    hasWaterLogo: false,//是否有水印
    tips_lookNum: [],
    adviser:[],//资讯列表
    index: -1, //第几条
    length: 10,
    total: 0, //共多少条
    isShowA:true//是否显示资讯
  },

  /**
   * 生命周期函数--监听页面加载
   */

  onLoad: function () {
    wx.setNavigationBarTitle({
      title: '楼盘详情'
    });
    if (app.globalData.xcxtype.hasLogo == '1') {
      //显示水印
      this.setData({
        hasWaterLogo: true
      })
    } else {
      this.setData({
        hasWaterLogo: false
      })
    };
    
    wx.hideTabBar();
    getApp().editTabBar();
  },

  onShow: function () {
    var that = this;
    that.queryWlpOnlookers();
    common.ajaxPost(
      'portal/wlpBuilding/queryBuilding.action', {
        id: app.globalData.bid
      },
      function (res) {
        console.log(res)
        that.setData({
          isLa: false
        })
        if (res && res.length > 0) {
          var data = res[0];
          var banner = data.banners.split(";");
          var tips = data.houseLable.split("|");
          var updateTime = data.updateTime.split(" ")[0];
          var longitude = data.longitude;
          var latitude = data.latitude;
          if (longitude && latitude && longitude != "undefined" && latitude !="undefined"){
            var position = common.bd09togcj02(data.longitude, data.latitude)
            that.setData({
              longitude: position[0],
              latitude: position[1],
              isLa:true
            })
          }
          that.setData({
            data: data,
            bannerList: banner,
            tips: tips,
            updateTime: updateTime,
            houseType: that.houseType(data.houseType),
          })
        }
      }
    ),
      that.getInformation();
  },
houseType:function(type){
  switch (type) {
    case 1: return '住宅'; break;
    case 2: return '公寓'; break;
    case 3: return '别墅'; break;
    case 4: return '商铺'; break;
    case 5: return '经济适用房'; break;
    case 6: return '两限房'; break;
    case 7: return '综合体'; break;
    default: break;
}
  },
  jiaotong: function () {
    this.setData({
      zhoubian_num: 1
    })
},
todetail: function () {
  console.log('跳转啊')
  wx.switchTab({
    url: '/pages/photos/photos'
  })
},
shenghuo: function () {
  this.setData({
    zhoubian_num: 2
  })
  },
  jiaoyu: function () {
    this.setData({
      zhoubian_num: 3
    })
},
glos: function (event) {
  var that = this;
  common.openPosition(this.data.latitude, this.data.longitude, this.data.data.address, this.data.data.addressDesc)
},
  zsgw:function(){
    wx.navigateTo({
      url: '/pages/adviserList/adviserList',
    })
},
  yykf:function(){
    wx.navigateTo({
      url: '/pages/order/order',
    })
  },
onShareAppMessage: function (res) {
  var that = this;
  return {
    title: '楼盘详情', 
    path: '/pages/index/index?type=detail&bid=' + app.globalData.bid + "&isIndex=1",
    success: function (res) {
      // 转发成功
      console.log(2)
    },
    fail: function (res) {
      // 转发失败
    }
  }
},
  changeTab: function (e) {
    var url=e.currentTarget.dataset.url;
    wx.switchTab({
      url: url
    })
  },
 
  queryWlpOnlookers:function(){
    var that=this;
    common.ajaxPost(
      'portal/wlpOnlookers/queryWlpOnlookers.action', {
        bid: app.globalData.bid,
      },
      function (res) {
        console.log(res);
        if (res && res.length>0) {
          var tipLook = res.data; var newtipLook=[];
           if(tipLook.length>6){
              newtipLook=tipLook.splice(0,6); 
              newtipLook.push("../../img/more.png");
           }else{
             newtipLook = res.data;
             newtipLook.push("../../img/more.png");
           }
        
            that.setData({
              tips_lookNum: newtipLook,
              recordsTotal: res.recordsTotal
            })
        }
      }
    )
  },

  call: function (e) {
    var that = this;
    console.log(e);
    wx.makePhoneCall({
      phoneNumber: e.currentTarget.dataset.tel //仅为示例，并非真实的电话号码
    })
    return false;
  },

  gotomore:function(){
    console.log(1);
    wx.navigateTo({
      url: '../moreNum/moreNum',
    })
  },

  //获取资讯详情
  getInformation: function () {
    //获取资讯信息
    var that = this;
    that.setData({
      index: -1, //第几条
      length: 10,
      total: 0,
      adviser: [], isShowA:true
    })
    var index = that.data.index;
    var length = that.data.length;
    if (index <= that.data.total) {
      index++;
      common.ajaxPost(
        'portal/wlpAdvisory/queryWlpAdvisoryPageList.action', {
          start: index,
          length: length,
          bid: app.globalData.bid,
        },
        function (res) {
          console.log(res);
          if (res && res.length > 0) {
            var list = that.data.adviser;
            list = list.concat(res.data);
            that.setData({
              adviser: list,
              total: res.recordsTotal,
              index: that.data.index + res.length,
            })
            if (res.recordsTotal == 0) {
              that.setData({
                isShowA:false
              })
            }
          } else {

          }
        }
      )
    }
  },
   gotozxDetail: function (e) {
    //跳转到资讯详情页
    console.log(e);
    var id = e.currentTarget.dataset.id;
    common.addPvNum(id);
    console.log(id);
    wx.navigateTo({
      url: '../zxDetail/zxDetail?id=' + id,
    })
  },
})